const app = getApp();
Page({
  data: {
    collectType:0,
    shopList:'',
    page: 1,
    loadStatus: false,
    not: false
  },
  // 取消收藏
  DelCollect: function (e) {
    let that = this;
    let id = e.target.dataset.id;
    wx.showModal({
      title: "提示",
      content: "确定要取消收藏？",
      success(res) {
        if (res.confirm) {
          wx.showLoading({
            title: '请求操作中...',
          })
          wx.request({
            url: app.buildUrl('/shop/shop/del-collection'),
            method: 'GET',
            data: {
              id: id
            },
            header: app.buildHeader(),
            success: function (res) {
              wx.hideLoading();
              app.showToast(res.data.msg)
              setTimeout(() => {
                that.setData({
                  shopList: that.data.shopList.filter(i => i.id != id)
                })
              }, 1000)
            }
          });
        }
      }
    })
  },
  // 加载更多
  loadMore() {
    let that = this;
    let page = that.data.page;
    if (that.data.loadStatus) { return; }
    if (that.data.not) { return; }
    that.setData({
      loadStatus: true
    })
    page = ++page;
    wx.showLoading({
      title: '加载更多...',
    })
    wx.request({
      url: app.buildUrl('/shop/shop/get-collection'),
      method: 'GET',
      data: {
        'page': page,
        'status': 1
      },
      header: app.buildHeader(),
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == 200) {
          if (res.data.data.length == 0) {
            app.showToast('没有更多了')
            that.setData({
              not: true
            });
          } else {
            that.setData({
              activityList: that.data.activityList.concat(res.data.data),
              page: page
            });
          }
        } else {
          app.showToast(res.data.msg)
        }
        that.setData({
          loadStatus: false
        })
      }
    });
  },
  load(){
    let that = this;
    wx.request({
      url: app.buildUrl('/shop/shop/get-collection'),
      method: 'GET',
      data: {
        'page': 1,
        'status': '1'
      },
      header: app.buildHeader(),
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == 200) {
          that.setData({
            shopList: res.data.data
          });
        } else {
          app.showToast(res.data.msg)
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({
      title: '加载中...',
    })
    this.load()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  }
})